import Vue from 'vue'
import VueRouter from 'vue-router'

// 正常写法
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Home'

// 路由懒加载的写法
const User = () => import(/* webpackChunkName: 'User' */ '@/views/User')
const Search = () => import(/* webpackChunkName: 'Search' */ '@/views/Search')
const SearchResultList = () => import(/* webpackChunkName: 'SearchResultList' */ '@/views/Search/ResultList')
const ArticleDetail = () => import(/* webpackChunkName: 'ArticleDetail' */ '@/views/Article/id')
const UserEdit = () => import(/* webpackChunkName: 'UserEdit' */ '@/views/User/Edit')
const Xiaosi = () => import(/* webpackChunkName: 'XIaosi' */ '@/views/Xiaosi')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // 根路径重定向
    redirect: '/layout'
  }, {
    path: '/login',
    component: Login
  }, {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home',
    children: [
      {
        path: 'home',
        component: Home
      }, {
        path: 'user',
        component: User
      }
    ]
  }, {
    path: '/search',
    component: Search
  }, {
    path: '/search/:name', // 动态路由
    component: SearchResultList
  }, {
    path: '/article',
    component: ArticleDetail
  }, {
    path: '/user/edit',
    component: UserEdit
  }, {
    path: '/xiaosi',
    component: Xiaosi
  }
]

const router = new VueRouter({
  routes
})

export default router
